#coding=utf-8
import ddt
import unittest
from business.register_business import RegisterBusiness
from selenium import webdriver
from HTMLTestRunner_api import HTMLTestRunner
from util.excel_util import ExcelUtil as ex
import os
from log.user_log import UserLog as log
from util.read_yaml import ReadIni

data = ex().get_data()
logger = log().get_log()


@ddt.ddt
class FirstDdtCase(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        option = webdriver.ChromeOptions()
        option.add_argument('--headless')
        cls.driver = webdriver.Chrome(chrome_options=option)
        cls.driver.get(ReadIni().get_value()['base']['url'])
        cls.driver.implicitly_wait(5)
        cls.login = RegisterBusiness(cls.driver)

    @classmethod
    def tearDownClass(cls):
        cls.driver.quit()

    @ddt.data(*data)
    def test_register_case(self,data):
        case_num,case_name,username,code,password_1,password_2,assertCode,assertText = data
        result = self.login.register_function(case_num,case_name,username,code,password_1,password_2,assertCode,assertText)
        if 'message' in result:
            self.assertTrue(False,result)
        else:
            self.assertEqual(assertText,result,'message：【期望结果】!=【实际结果】')

if __name__ == '__main__':
    dir01 = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
    file_path = os.path.join(dir01+"\\report\\"+"first_case1.html")
    f = open(file_path,'wb')
    suite = unittest.TestLoader().loadTestsFromTestCase(FirstDdtCase)
    runner = HTMLTestRunner(stream=f,
                            title="This is first report1",
                            description="这个是我们第一次测试报告",
                            verbosity=2)
    runner.run(suite)
    # unittest.main()
